<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/fragments/head">
<title>授权</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<div th:replace="admin/fragments/header"></div>
		<div th:replace="admin/fragments/mainsidebar::mainside('资源管理','user')"></div>

		<div class="content-wrapper">
			<section class="content-header">
				<h1>资源编辑</h1>
			</section>

			<section class="content">
				<div class="row">
					<div class="col-md-12">
						<div class="box  box-primary">
							<form class="form-horizontal form-grant">
								<div class="box-body">
									<div class="form-group">
										<div class="col-sm-12">
											<div class="checkbox i-checks" th:each="item:${list}">
												<label th:switch="${#lists.contains(roleIds,item.id)}">
													<input th:case="true" th:text="${item.roleName}" name="roleIds"  th:value="${item.id}"
													type="checkbox" checked="true" /> <input th:case="false" name="roleIds" th:value="${item.id}"
													th:text="${item.roleName}" type="checkbox" />
												</label>
												<!-- <input th:text="${item.roleName}" type="checkbox"
													name="roleIds" th:value="${item.id}"
													th:checked="${#lists.contains(roleIds,item.id)?'checked':''}" /> -->
											</div>
										</div>
									</div>
								</div>
								<div class="box-footer">
									<button type="button" class="btn btn-default btn-back">返回</button>
									<button type="button"
										class="btn btn-info pull-right btn-submit">提交</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</section>
		</div>

		<div th:replace="admin/fragments/footer"></div>
	</div>

	<div th:replace="admin/fragments/script"></div>
	<script th:inline="javascript">
	/*<![CDATA[*/
	   $(".btn-submit").click(function () {
	        $.ajax({
	            type: "POST",
	            dataType: "json",
	            url: "/admin/user/grant/" + [[${user.id}]],
	            data: $(".form-grant").serialize(),
	            success: function (res) {
	                layer.msg(res.message, {time: 2000}, function () {
	                    location.reload();
	                });
	            }
	        });
	    });
	    /*]]>*/
	</script>
</body>
</html>